const sql = require("../../mysql");

module.exports = async ctx => {
  try {
    console.log(ctx.request.userRole);

    if (ctx.request.userRole !== "admin") {
      ctx.body = {
        code: -1,
        msg: "没有权限"
      };
      return;
    }
    let userList = await sql.User.findAll({
      attributes: ["uname", "createdAt", "updatedAt", "id", "role", "status"],
      where: {
        role: {
          [sql.Op.not]: "admin"
        }
      }
    });

    ctx.body = {
      code: 0,
      data: userList
    };
  } catch (error) {
    ctx.response.status = 200;

    ctx.body = {
      code: -1,
      msg: error.errors ? error : error.errors[0].message
    };
  }
};
